import request from "./request";
import type { IOptions } from "./types";

class Http {
  private baseUrl: string;
  constructor(baseUrl: string = "") {
    this.baseUrl = baseUrl;
  }

  // get('/xx', { query: { xxx } })
  // get<T>(url: string, options: IOptions<T> = {}) {
  //   return request<T>(this.baseUrl + url, {
  //     ...options,
  //     method: "GET",
  //   });
  // }

  // get('/xx', { xxx })
  get<T>(url: string, query: Object = {}, options: IOptions<T> = {}) {
    return request<T>(this.baseUrl + url, {
      ...options,
      method: "GET",
      query,
    });
  }

  post<T>(url: string, body: Object = {}, options: IOptions<T> = {}) {
    return request<T>(this.baseUrl + url, {
      ...options,
      method: "POST",
      body,
    });
  }

  put<T>(url: string, body: Object = {}, options: IOptions<T> = {}) {
    return request<T>(this.baseUrl + url, {
      ...options,
      method: "PUT",
      body,
    });
  }

  delete<T>(url: string, query: Object = {}, options: IOptions<T> = {}) {
    return request<T>(this.baseUrl + url, {
      ...options,
      method: "DELETE",
      query,
    });
  }
}

export default Http;
